module Film where
import IdObject

-- stan dvd
data State = Available | Loaned | Lost deriving (Show, Read, Eq, Enum)

type FilmInfo = (String, -- tytul
		Int, -- rok produkcji
		String, -- rezyser
		String, -- gatunek
		State,
		String) -- opis 

data Film =
	Film Int FilmInfo
	deriving (Show, Read)

instance Eq Film where
	(Film id1 _) == (Film id2 _) = id1 == id2

instance Ord Film where
        film1 < film2     | (getTitle film1 < getTitle film2)        = True
                          | (getTitle film1 > getTitle film2)        = False
                          | (getYear film1 < getYear film2)          = True
                          | (getYear film1 > getYear film2)          = False
                          | (getDirector film1 < getDirector film2)  = True
                          | (getDirector film1 > getDirector film2)  = False
                          | (getKind film1 < getKind film2)          = True
                          | otherwise                                = False
        film1 <= film2    | (getTitle film1 < getTitle film2)        = True
                          | (getTitle film1 > getTitle film2)        = False
                          | (getYear film1 < getYear film2)          = True
                          | (getYear film1 > getYear film2)          = False
                          | (getDirector film1 < getDirector film2)  = True
                          | (getDirector film1 > getDirector film2)  = False
                          | (getKind film1 < getKind film2)          = True
                          | (getKind film1 > getKind film2)          = False
                          | otherwise                                = True
        film1 > film2     = not (film1 <= film2)
        film1 >= film2    = not (film1 < film2)

instance IdObjectClass Film where
        getId (Film i f) = i
        getParam paramId film   | paramId == 1  = (getTitle film)
                                | paramId == 2  = show (getYear film)
                                | paramId == 3  = (getDirector film)
                                | paramId == 4  = (getKind film)
                                | paramId == 5  = show (getState film)
                                | paramId == 6  = (getDescription film)
                                | otherwise     = ""
        getParamNum film = 6
        toList film = (show (getId film)) : (getTitle film) : (show (getYear film)) 
                : (getDirector film) : (getKind film) 
                : (show (getState film)) : (getDescription film) : []
--	empty = Film 0 ("",0,"","",Available,"")

{- Funkcje get dla kazdego z parametrow-}
getFilmInfo :: Film -> FilmInfo
getFilmInfo (Film i f) = f

getTitle :: Film -> String
getTitle (Film i (title, year, director, kind, available, description)) = title

getYear :: Film -> Int
getYear (Film i (title, year, director, kind, available, description)) = year

getDirector :: Film -> String
getDirector (Film i (title, year, director, kind, available, description)) = director

getKind :: Film -> String
getKind (Film i (title, year, director, kind, available, description)) = kind

getState :: Film -> State
getState (Film i (title, year, director, kind, state, description)) = state

getDescription :: Film -> String
getDescription (Film i (title, year, director, kind, available, description)) = description

-- Funkcje set
setTitle :: Film -> String -> Film
setTitle (Film i (title, year, director, kind, available, description)) new = (Film i (new, year, director, kind, available, description))

setYear :: Film -> Int -> Film
setYear (Film i (title, year, director, kind, available, description)) new = (Film i (title, new, director, kind, available, description))

setDirector :: Film -> String -> Film
setDirector (Film i (title, year, director, kind, available, description)) new = (Film i (title, year, new, kind, available, description))

setKind :: Film -> String -> Film
setKind (Film i (title, year, director, kind, available, description)) new = (Film i (title, year, director, new, available, description))

setState :: Film -> Int -> Film
setState (Film i (title, year, director, kind, state, description)) new = (Film i (title, year, director, kind, newState, description))
	where newState	| new == 1	= Available
			| new == 2	= Loaned
			| new == 3 	= Lost

setDescription :: Film -> String -> Film
setDescription (Film i (title, year, director, kind, available, description)) new = (Film i (title, year, director, kind, available, new))


display :: Film -> String
display (Film i (title, year, director, kind, state, description)) = 
        "| " ++ (show i) ++ " | " ++ title ++ " | " ++
        (show year) ++ " | " ++ director ++ " | " ++ kind ++ 
        " | " ++ (show state) ++ " | " ++ description ++ " |"

-- porownuje, czy to kopie tego samego filmu, tzn. ten sam tytul, rezyser oraz rok prod., ale inne id
sameFilm :: Film -> Film -> Bool
sameFilm f1 f2	| (getTitle f1 == getTitle f2)
			&& (getYear f1 == getYear f2)
			&& (getDirector f1 == getDirector f2)
			&& (getKind f1 == getKind f2)		= True
		| otherwise					= False
